package top.linyuxb.lycloud.config.samples.client.service.impl;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import top.linyuxb.lycloud.config.samples.client.config.UserConfig;
import top.linyuxb.lycloud.config.samples.client.entity.UserBaseInfoEntity;
import top.linyuxb.lycloud.config.samples.client.repository.UserBaseInfoRepository;
import top.linyuxb.lycloud.config.samples.client.service.IUserBaseInfoService;
import top.linyuxb.lycloud.config.starter.annotation.LyConfigListener;
import top.linyuxb.lycloud.config.starter.annotation.LyConfigurationValue;
import top.linyuxb.lycloud.config.starter.common.ChangeTypeEnum;

import java.util.List;

/**
 * Created by Intellij IDEA.
 *
 * @Author: linyuxb
 * @Date: 2024/6/14 11:34
 * @Desc:
 */
@Lazy
@Slf4j
@Service(value = "userBaseInfoService")
public class UserBaseInfoServiceImpl implements IUserBaseInfoService {
    @LyConfigurationValue(value = "${default.key01:3}")
    private Integer key01;
    @LyConfigurationValue(value = "${default.key02}")
    private String key02;
    @Resource
    private UserConfig userConfig;

    @Resource
    private UserBaseInfoRepository userBaseInfoRepository;

    @Override
    public List<UserBaseInfoEntity> getUserInfos() {
        return userBaseInfoRepository.findAll();
    }

    @Override
    public Integer getKey01() {
        return key01;
    }

    @Override
    public String getKey02() {
        return key02;
    }

    @Override
    public UserConfig getUserConfig() {
        return userConfig;
    }

    @Override
    @LyConfigListener(keys = {"default.key01", "default.key02"}, changeType = ChangeTypeEnum.ALL)
    public void testListener1() {
        log.info("testListener1 :{},{}", key01, key02);
    }

    @Override
    @LyConfigListener(keys = "default.key02")
    public void testListener2() {
        log.info("testListener2 :{}", key01);
    }

    @Override
    @LyConfigListener(keys = "default.key01")
    public void testListener3() {
        log.info("testListener3 :{}", key01);
    }
}
